﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using MvcContrib.FluentHtml;

using Revis.VClinicNet.App.Internal.Dto;
using Revis.VClinicNet.Core.Domain.Credentials;
using Revis.VClinicNet.Util.Translation;

namespace Revis.VClinicNet.UI.Internal.Mvc.Models.Forms
{
    public static class PatientEditDtoFormExtensions
    {
        private static readonly string DoctorSelectKey = "DoctorsSelectList";

        public static IEnumerable<SelectListItem> DoctorList(
            this PatientEditDto dto, ViewDataDictionary viewData)
        {
            return viewData[DoctorSelectKey] as IEnumerable<SelectListItem>;
        }

        public static void SetDoctorList(
            this PatientEditDto dto,
            ViewDataDictionary viewData,
            IList<DoctorInfoDto> doctorsList)
        {
            List<SelectListItem> items = doctorsList.Select(d => {
                return new SelectListItem() {
                    Text = d.Name,
                    Value = d.Id.ToString(),
                    Selected = d.Id == dto.DoctorId
                };
            }).ToList();
            viewData[DoctorSelectKey] = items;
        }
    }
}